import * as echarts from 'echarts'
import { useEffect, useRef } from 'react'
function Bar ({ title, xData, yData, style }) {
  const dom = useRef()

  const chartInit = () => {
    const myChart = echarts.init(dom.current)

    // 指定图表的配置项和数据
    var option = {
      title: {
        text: title
      },
      tooltip: {},
      legend: {
        data: yData
      },
      xAxis: {
        data: xData
      },
      yAxis: {},
      series: [
        {
          name: '销量',
          type: 'bar',
          data: [5, 20, 36, 10, 10, 20]
        }
      ]
    }

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option)
  }
  useEffect(() => {
    chartInit()
  }, [])
  return (
    <div>
      <div ref={dom} style={style}></div>
    </div>
  )
}

export default Bar